/*
 *   
 *
 * Copyright  1990-2009 Sun Microsystems, Inc. All Rights Reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License version
 * 2 only, as published by the Free Software Foundation.
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License version 2 for more details (a copy is
 * included at /legal/license.txt).
 * 
 * You should have received a copy of the GNU General Public License
 * version 2 along with this work; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 * 
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
 * Clara, CA 95054 or visit www.sun.com if you need additional
 * information or have any questions.
 */

class EntryActivationDesc: public OopDesc { 
 public:
  static jint header_size() { return sizeof(EntryActivationDesc); }

  // Computes the allocation size
  static size_t allocation_size(int length) { 
    return align_allocation_size(header_size() + length * 2 * sizeof(OopDesc*));
  }
  
  // Returns the object size
  size_t object_size() { return allocation_size(_length); }

  // GC support.
  void variable_oops_do(void do_oop(OopDesc**));

 private:
  // Initializes the object after allocation
  void initialize(OopDesc* klass, jint length) {
    OopDesc::initialize(klass);
    _length = length;
  }
  static jint base_offset(jint index, jint length) {
    GUARANTEE(index >= 0 && index < length, "out of bounds");
    (void)length;
    return header_size() + 2 * index * sizeof(OopDesc*);
  }

  // The parameter pushing code in shared_entry must be careful to 
  // push these in the right order. The order of tag vs. value differs on
  // various architectures.
  static jint value_offset   (jint index, jint length) { 
    return base_offset(index, length) + 0 * BytesPerWord; 
  }
  static jint tag_offset     (jint index, jint length) { 
    return base_offset(index, length) + 1 * BytesPerWord; 
  }
  jint tag_offset   (jint index) const { return tag_offset   (index, _length); }
  jint value_offset (jint index) const { return value_offset (index, _length); }

  // accessors used by variable oops do
  Tag       tag_at             (jint index) const { return *((Tag*)field_base(tag_offset(index)));     }
  OopDesc** pointer_to_value_at(jint index) const { return (OopDesc**)field_base(value_offset(index)); }

  jint                 _length;
  MethodDesc*          _method;
  EntryActivationDesc* _next;
#if USE_REFLECTION || ENABLE_JAVA_DEBUGGER || ENABLE_JNI
  address              _return_point;
#endif

  friend class EntryActivation;
  friend class Universe;
};
